﻿// <copyright file="VfsMappingList.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// This class represents a list of VFS mapping entries.
    /// </summary>
    internal class VfsMappingList
    {
        /// <summary>
        /// The list of VFS mappings contained in the CP file.
        /// </summary>
        private List<VfsMappingListEntry> mappingList;

        /// <summary>
        /// Initializes a new instance of the VfsMappingList class.
        /// </summary>
        /// <param name="dataStream">
        /// A memory stream that contains the raw data for this section of the CP file.
        /// </param>
        public VfsMappingList(System.IO.MemoryStream dataStream)
        {
            this.mappingList = new List<VfsMappingListEntry>();
            this.ReadSection(dataStream);
        }

        /// <summary>
        /// Gets the list of VFS mapping entries.
        /// </summary>
        public List<VfsMappingListEntry> MappingList
        {
            get { return this.mappingList; }
        }

        /// <summary>
        /// Reads the actual data for this section from the file.
        /// </summary>
        /// <param name="dataStream">
        /// A MemoryStream containing the raw data for the section.
        /// </param>
        private void ReadSection(System.IO.MemoryStream dataStream)
        {
            System.IO.BinaryReader streamReader = new System.IO.BinaryReader(dataStream);

            VfsMappingListEntry entry;
            while (streamReader.BaseStream.Position != streamReader.BaseStream.Length)
            {
                entry = new VfsMappingListEntry(dataStream);
                this.mappingList.Add(entry);
            }

            streamReader.Close();
        }
    }
}
